import Vue from 'vue'
import Router from 'vue-router'
import Login from '@/components/login/Login.vue'
import NumLogin from '@/components/login/NumLogin.vue'
import Home from '@/components/home/Home'
import Register from '@/components/register/Register'
import Verify from '@/components/register/Verify'
import Dailysongs from '@/components/finelist/Dailysongs'
import Playsong from '@/components/playsong/Playsong'
import Blog from '@/components/home/Blog'
import My from '@/components/home/My'
import Focus from '@/components/home/Focus'
import Village from '@/components/home/Village'
import Songlist from '@/components/home/Songlist'
import Playsongremark from '@/components/playsong/Playsongremark'
import Presonfm from '@/components/playsong/Presonfm'
import Search from '@/components/search/Search'

Vue.use(Router)



const router = new Router({
  routes: [
    {
      path: '/',
      name: 'login',
      component: Login,
    },
    {
      path: '/search',
      name: 'search',
      component: Search,
    },
    {
      path: '/presonfm',
      name: 'presonfm',
      component: Presonfm,
    },
    {
      path: '/numLogin',
      name: 'numLogin',
      component: NumLogin
    },
    {
      path: '/home',
      name: 'home',
      component: Home
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/verify',
      name: 'verify',
      component: Verify
    },
    {
      path: '/dailysongs',
      name: 'dailysongs',
      component: Dailysongs
    },
    {
      path: '/playsong',
      name: 'playsong',
      component: Playsong,
    },
    {
      path: '/blog',
      name: 'blog',
      component: Blog
    },
    {
      path: '/my',
      name: 'my',
      component: My
    },
    {
      path: '/foucs',
      name: 'foucs',
      component: Focus
    },
    {
      path: '/village',
      name: 'village',
      component: Village
    },
    {
      path: '/songlist',
      name: 'songlist',
      component: Songlist
    },
    {

      path: '/playsongremark',
      name: 'playsongremark',
      component: Playsongremark,
    },
  ]
})

router.beforeEach((to, from, next) => {
  // to 将要访问的路径
  // from 代表从哪个路径跳转而来
  // next 是一个函数，表示放行
  //     next()  放行    next('/login')  强制跳转

  if (to.path === '/numLogin') return next()
  // 获取token
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/numLogin')
  next()
})

export default router


